package cmpe451.group7.ourcity.util;

import cmpe451.group7.ourcity.entity.Comment;
import cmpe451.group7.ourcity.entity.Multimedia;
import cmpe451.group7.ourcity.entity.Place;
import cmpe451.group7.ourcity.entity.User;

import com.google.gson.ExclusionStrategy;
import com.google.gson.FieldAttributes;

/**
 * This class is created to remove the binary fields from an entity before
 * converting them to JSON.
 * 
 * TODO We can continue without this class, if we can handle the "lazy loading"
 * issue at Hibernate side.
 */
public class JSONExclusionStrategy implements ExclusionStrategy {

	public boolean shouldSkipClass(Class<?> arg0) {
		return false;
	}

	public boolean shouldSkipField(FieldAttributes f) {
		return checkMultimedia(f)
		// || checkComment(f)
				|| checkUser(f) || checkPlace(f);
	}

	private boolean checkMultimedia(FieldAttributes f) {
		return (f.getDeclaringClass() == Multimedia.class && (f.getName()
				.equals("file") || f.getName().equals("owner")));
	}

	private boolean checkComment(FieldAttributes f) {
		return (f.getDeclaringClass() == Comment.class && (f.getName()
				.equals("user")));
	}

	private boolean checkPlace(FieldAttributes f) {
		return (f.getDeclaringClass() == Place.class && (f.getName()
				.equals("tags")));
	}

	private boolean checkUser(FieldAttributes f) {
		return (f.getDeclaringClass() == User.class && (f.getName().equals(
				"password") || f.getName().equals("likedPlace")));
	}

}